<?php
namespace Admin\Controller;

use Common\Base\ControllerBase;
use Common\Logic\Admin\AdminLogic;
use Common\Logic\Admin\NodeLogic;

class IndexController extends ControllerBase
{
    public function index()
    {
        $L_admin = new AdminLogic();
        $L_node = new NodeLogic();

        $menus = array();
        $topMenus = array();
        $subMenus = array();
        $tmp=array();

        $supers = C('ROOT_MEMBER_ID');
        if(in_array(ADMIN_ID, $supers))
        {
            //如果是root帐号
            $tmp = $L_node->getNodeList(2, array('st'=>1, 'lt_node_level'=>4), '*', 0, 0, 'px asc');
        }
        else
        {
            //其他帐号
            if(session('admin_acl')){                                            
                $tmp = $L_node->getNodeList(2, array('st'=>1, 'node_ids'=>session('admin_acl'), 'lt_node_level'=>4), '*', 0, 0, 'px asc');
            }
        }
        //整理
        $menus = list_to_tree($tmp, 'node_id', 'node_pid'); unset($tmp);

        foreach ($menus as $v){
            $topMenus[$v['node_id']] = $v; unset($topMenus[$v['node_id']]['_child']);
            $subMenus[$v['node_id']] = $v['_child'];
        }
        unset($menus);

        $this->assign('topMenus', $topMenus);
        $this->assign('subMenus', $subMenus);
        $this->display();
    }

    public function home()
    {
        $info = array(
            '操作系统'=>PHP_OS,
            '运行环境'=>$_SERVER["SERVER_SOFTWARE"],
            'PHP运行方式'=>php_sapi_name(),
            '上传附件限制'=>ini_get('upload_max_filesize'),
            '执行时间限制'=>ini_get('max_execution_time').'秒',
            '服务器时间'=>date("Y年n月j日 H:i:s"),
            '北京时间'=>gmdate("Y年n月j日 H:i:s",time()+3600*8),
            '服务器域名/IP'=>$_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
            //'剩余空间'=>round((@disk_free_space(".")/(1024*1024)),2).'M',
            'register_globals'=>get_cfg_var("register_globals")=="1" ? "ON" : "OFF",
            'magic_quotes_gpc'=>(1===get_magic_quotes_gpc())?'YES':'NO',
            'magic_quotes_runtime'=>(1===get_magic_quotes_runtime())?'YES':'NO',
        );
        $this->assign('info', $info);
        $this->display();
    }

    public function pub_change_password()
    {
        if(IS_POST && isset($_POST['do'])){
            $post = I('post.');
            $L_admin = new AdminLogic();
            $rs = $L_admin->changePassword($post, session('admin_id'));
            if(false === $rs){
                $this->ajaxReturn(genReturn('n', $L_admin->getError()));
            }else{
                $this->ajaxReturn(genReturn('y', 'ok'));
            }
        }
        $this->display();
    }

    public function pub_send_email()
    {
        $this->display();
    }

    public function pub_send_sms()
    {
        $this->display();
    }

    //打印session
    public function dump_session()
    {
        dump($_SESSION);
    }

    //打印cookie
    public function dump_cookie()
    {
        dump($_COOKIE);
    }

    //打印post
    public function dump_post()
    {
        dump($_POST);
    }

    //打印get
    public function dump_get()
    {
        dump($_GET);
    }

    //打印server
    public function dump_server()
    {
        dump($_SERVER);
    }

    //关于系统
    public function about()
    {
        exit('<div>管理平台<br><br><input type="button" value="close" onclick="closeZuiModal();" class="btn btn-success" /></div>');
    }
}